package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.pt.MallPtSignCouponRecord;
import com.tencreat.domain.pt.vo.ResMallPtSignCouponRecordVo;
import com.tencreat.service.pt.IMallPtSignCouponRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author tencreat
 * @date 2021-12-09
 */
@Api(tags="拼团卷使用详情api")
//@RestController
@RequestMapping("/pt/record")
public class MallPtSignCouPonRecordController extends BaseController{

    //@Autowired
    private IMallPtSignCouponRecordService mallPtSignCouponRecordService;

    /**
     * 查询拼团卷使用详情列表
     */
    @ApiOperation(value="查询拼团卷使用详情列表")
    @PreAuthorize("@ss.hasPermi('pt:record:list')")
    @PostMapping("/list")
    public HttpResult<IPage<MallPtSignCouponRecord>> list(@RequestBody  MallPtSignCouponRecord mallPtSignCouponRecord) {
        QueryWrapper<MallPtSignCouponRecord> wrapper = Wrappers.query(mallPtSignCouponRecord);
        Page<MallPtSignCouponRecord> page =  new Page<>(mallPtSignCouponRecord.getPageNum(), mallPtSignCouponRecord.getPageSize());
        return HttpResult.ok(mallPtSignCouponRecordService.page(page, wrapper));
    }

    /**
     * 拼团卷使用列表
     */
    @ApiOperation(value="查询拼团卷使用详情列表")
    @PostMapping("/signList")
    public HttpResult<IPage<ResMallPtSignCouponRecordVo>> signList(@RequestBody ResMallPtSignCouponRecordVo mallPtSignCouponRecordvo) {
        Page<ResMallPtSignCouponRecordVo> page =  new Page<>(mallPtSignCouponRecordvo.getPageNum(), mallPtSignCouponRecordvo.getPageSize());
        return HttpResult.ok(mallPtSignCouponRecordService.signList(page, mallPtSignCouponRecordvo));
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @ApiOperation(value="导出【请填写功能名称】列表")
    @PreAuthorize("@ss.hasPermi('pt:record:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallPtSignCouponRecord mallPtSignCouponRecord) {
        List<MallPtSignCouponRecord> list = mallPtSignCouponRecordService.selectMallPtSignCouponRecordList(mallPtSignCouponRecord);
        ExcelUtil<MallPtSignCouponRecord> util = new ExcelUtil<MallPtSignCouponRecord>(MallPtSignCouponRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @ApiOperation(value="获取【请填写功能名称】详细信息")
    @PreAuthorize("@ss.hasPermi('pt:record:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallPtSignCouponRecord> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(mallPtSignCouponRecordService.selectMallPtSignCouponRecordById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation(value="新增【请填写功能名称】")
    @PreAuthorize("@ss.hasPermi('pt:record:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  MallPtSignCouponRecord mallPtSignCouponRecord) {
        return to(mallPtSignCouponRecordService.insertMallPtSignCouponRecord(mallPtSignCouponRecord));
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation(value="修改【请填写功能名称】")
    @PreAuthorize("@ss.hasPermi('pt:record:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallPtSignCouponRecord mallPtSignCouponRecord) {
        return to(mallPtSignCouponRecordService.updateMallPtSignCouponRecord(mallPtSignCouponRecord));
    }

    /**
     * 删除【请填写功能名称】
     */
    @ApiOperation(value="删除【请填写功能名称】")
    @PreAuthorize("@ss.hasPermi('pt:record:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(mallPtSignCouponRecordService.deleteMallPtSignCouponRecordByIds(ids));
    }
}
